package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.service.OrderSettingListService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.dom.DOMCryptoContext;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/ordersettinglist")
public class OrderSettingListController {

    @Reference
    private OrderSettingListService orderSettingListService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = orderSettingListService.findPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize(), queryPageBean.getQueryString());
        return pageResult;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Map map, Integer[] setmealIds){
        try{
            Member member = new Member();
            Order order = new Order();
            member.setName((String)map.get("name"));
            member.setIdCard((String) map.get("idCard"));
            //member.setBirthday((Date) map.get("birthday"));
            member.setPhoneNumber((String) map.get("phoneNumber"));
            member.setSex((String) map.get("sex"));

            //order.setOrderDate((Date) map.get("orderDate"));
            order.setSetmealId(setmealIds[1]);

            orderSettingListService.add(member,order);
            return new Result(true,MessageConstant.ORDER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDER_FULL);
        }
    }
}
